package datamining.visualisation;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.Properties;
import java.util.Vector;

import javax.swing.JTabbedPane;

import settings.Settings;

import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableColumnModel;

import datamining.sequence.HPSequence;
import de.parsemis.visualisation.gui.MyTab;



/** 
 * 创建于 2012-11-21 下午12:47:04
 * 
 * @author xujinghu (jinghuxu@nudt.edu.cn)
 * 
 * Copyright 2012 xujinghu
 * 
 * Lisence: Apache
 */
public class ViewTabbedPanel extends JTabbedPane implements ActionListener,PropertyChangeListener  {
	

	private SequenceViewTab tabs[] = null;
	private int tabsNumber = 4;
	private boolean setHighQuality = true;
	private Properties props;
	private ArrayList<HPSequence> sequencesHP; 
	
	public ViewTabbedPanel(Properties props){
		this.props = props;
		initTabs();
		

	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void propertyChange(PropertyChangeEvent evt) {
		final String propertyName = evt.getPropertyName();
		System.err.println(this.getClass().getName() + " property changed "
				+ propertyName);
		
		if (propertyName.equals(UIEvents.empty_tab)) {
			this.repaint();
			return;
		}
		
		if (propertyName.equals(UIEvents.add_sequences)) {
			tabs[0].setSequences(sequencesHP);
			addTab(null, tabs[0]);
			this.repaint();
			return;
		}
		
	}
	
	private void initTabs(){
		if (tabs == null) {
			tabs = new SequenceViewTab[tabsNumber];
			for (int i = 0; i < tabsNumber; i++) {
				tabs[i] = new SequenceViewTab(i, props);
				this.addPropertyChangeListener("remove all", tabs[i]);
			}

			tabs[0].addPropertyChangeListener("fragment selected", this);
			tabs[1].addPropertyChangeListener("graph selected", this);
			tabs[2].addPropertyChangeListener("embedding selected", this);
			this.addPropertyChangeListener("remove old data", tabs[1]);
			firePropertyChange("high quality",!setHighQuality , setHighQuality);
			addTab(props.getProperty("tab_sequence"), tabs[0]);
		}
	}
	
	public void setSequences(ArrayList<HPSequence> freqHPSequences) {
		sequencesHP =  freqHPSequences;
	}
	
}
